var paysetting = {
		
	load : function () {
		Ext.QuickTips.init();
		this.eventRegister();
		this.init();
	 
	},
	 
	eventRegister : function () {
		Ext.get("confirm").on('click',this.confrim);  //確認,新增使用者		
	},
	init:function(){
	    $.ajax({
	        url: '/ad/sys/com/control/PaysettingService.php',
	        cache: false,
	        dataType: 'json',
	            type:'get',
	        data: { action: 'getInfo'
	            },
	        error: function(xhr) {
	          alert('Ajax request 發生錯誤');
	        },
	        success: function(response) {
	                  var arrays=(response);
		                 $("#cpm").val(arrays[0].CPM);
		                 $("#cpc").val(arrays[0].CPC);
		                 $("#cpmPublish").val(arrays[0].CPMPublish);
		                 $("#cpcPublish").val(arrays[0].CPCPublish);
	         
	        }
	    });

	},
	
	confrim : function () {	   
		var cpm = Ext.getDom("cpm").value;
		var cpc = Ext.getDom("cpc").value;
		var cpmPublish = Ext.getDom("cpmPublish").value;
		var cpcPublish = Ext.getDom("cpcPublish").value;
		
		if (cpm == "") {
			alert("請輸入[cpm]!");
			return;
		}
		if (cpc == "") {
			alert("請輸入[cpc]!");
			return;
		}
		if (cpmPublish == "") {
			alert("請輸入[cpmPublish]!");
			return;
		}
		if (cpcPublish == "") {
			alert("請輸入[cpcPublish]!");
			return;
		}
		
	 	 
		 
	    Ext.Ajax.request({
	    	method : "POST",
	     	form : "cpcForm",
	    	callback : function (options, se, rsp) {
	    		var obj = rsp.responseText.toJSON();  
				//alert(rsp.responseText);

	    		if (obj.result =="1") {
	    			alert("設定成功!");
	    		} else{
	    			alert(obj);
	    		}
	    	}
	    	
	    });
	    //document.getElementById("userForm").submit();
 	}  
};

Ext.onReady(function (){
	paysetting.load();
});


